# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Kyle Keen <keenerd@gmail.com>
# Maintainer (Arch Linux): Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor (Arch Linux): Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor (Arch Linux): arjan <arjan@archlinux.org>
# Contributor (Arch Linux): Tom Newsom <Jeepster@gmx.co.uk>

_realname=ucl
pkgname=("ucl" "ucl-devel")
pkgver=1.03
pkgrel=1
pkgdesc="Portable lossless data compression library written in ANSI C"
arch=('i686' 'x86_64')
license=('GPL')
url="http://www.oberhumer.com/opensource/ucl/"
source=("http://www.oberhumer.com/opensource/${_realname}/download/${_realname}-$pkgver.tar.gz"
        "000-msys2.patch"
        "001-autoconf-compat.patch"
        "002-missing-macros.patch"
        "003-no-undefined.patch")
md5sums=('852bd691d8abc75b52053465846fba34'
         '6643b0a658d818075533e09046ce9ac9'
         'd370f7a7d07a76b0bfc76c50c73aaaad'
         'c18f77b87934abda7948dbbada817b14'
         '39ca38f60c03df634284552e69d5b775')

prepare() {
  cd "${_realname}-$pkgver"
  rm -f acinclude.m4
  patch -p1 -i "${srcdir}/000-msys2.patch"
  patch -p1 -i "${srcdir}/001-autoconf-compat.patch"
  patch -p1 -i "${srcdir}/002-missing-macros.patch"
  patch -p1 -i "${srcdir}/003-no-undefined.patch"

  touch ChangeLog
  WANT_AUTOMAKE=latest autoreconf -fiv
}

build() {
  cd "${_realname}-$pkgver"
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --disable-asm

  make
  make DESTDIR=${srcdir}/dest install
}

package_ucl() {
  mkdir -p ${pkgdir}/usr
  cp -rf $srcdir/dest/usr/bin ${pkgdir}/usr/
  
  install -Dm644 "${srcdir}/${pkgname}-${pkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_ucl-devel() {
  groups=('development')
  options=(staticlibs)
  depends=("ucl=${pkgver}")
  pkgdesc="ucl headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf $srcdir/dest/usr/include ${pkgdir}/usr/
  cp -rf $srcdir/dest/usr/lib ${pkgdir}/usr/
}
